package com.carkeeper.caruser.contorller;

import com.carkeeper.caruser.pojo.Car;
import com.carkeeper.caruser.service.CarService;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

@RestController
@RequestMapping("/car")
@Api(value = "车辆")
@CrossOrigin
public class CarController {

    @Autowired
    private CarService carService;

    /**
     * 根据用户id查询车辆信息
     * @param userId
     * @return
     */
    @ApiOperation(value = "根据用户id查询车辆信息")
    @ApiImplicitParam(name = "userId",value = "用户id",required = true)
    @GetMapping("/findCarByUserId")
    public Result<List<Car>> findCarByUserId(@RequestParam("userId") BigInteger userId) {
        List<Car> carList = carService.findCarByUserId(userId);
        if (carList == null || carList.size() <= 0) {
            return new Result<>(false, StatusCode.ERROR, "查询车辆失败");
        } else {
            return new Result<>(true, StatusCode.OK, "查询车辆成功",carList);
        }
    }
}
